package com.jing.product.controller;

import com.jing.common.core.domain.R;
import com.jing.common.core.web.controller.BaseController;
import com.jing.common.core.web.page.TableDataInfo;
import com.jing.product.domain.dto.PmsProductAttributeCategoryDTO;
import com.jing.product.domain.po.PmsProductAttributeCategoryPO;
import com.jing.product.domain.vo.PmsProductAttributeCategoryVO;
import com.jing.product.service.PmsCategotyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/category")
@Api(tags = "商品类型表")
public class ProductAttributeCategoryController extends BaseController {
    @Autowired
    private PmsCategotyService pmsCategotyService;


    /**
     * 测试商品类型分类分页
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "测试商品类型分类分页")
    public TableDataInfo page(@RequestParam(required = false,defaultValue = "1")
                                          Integer pageNum,
                              @RequestParam(required = false,defaultValue = "2")
                              Integer pageSize){
        startPage();
        List<PmsProductAttributeCategoryVO> list = pmsCategotyService.page();

        TableDataInfo dataTable = getDataTable(list);

        return dataTable;
    }


    @PostMapping("/add")
    @ApiOperation("添加商品类型")
    public R add(@Valid @RequestBody PmsProductAttributeCategoryPO productAttributeCategory){
        pmsCategotyService.add(productAttributeCategory);
        return R.ok("添加成功");
    }

    @PostMapping("/delect")
    @ApiOperation("删除商品类型")
    public R delect(@Valid @RequestParam String id){
        pmsCategotyService.delect(id);
        return R.ok("删除成功");
    }


    @PostMapping("/update")
    @ApiOperation("修改商品类型")
    public R update(@Valid @RequestBody PmsProductAttributeCategoryDTO productAttributeCategoryDTO){
        pmsCategotyService.update(productAttributeCategoryDTO);
        return R.ok("修改成功");
    }

}
